package com.app.babygo;

import com.app.babygo.dbservice.AchievementAdapter;
import com.app.babygo.help.MessageHelper;
import com.app.babygo.obj.AchievementTask;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class TaskCreation extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_task_creation);
	}
	
	public void createTask(View view) {
		EditText task_title = (EditText) findViewById(R.id.task_title_input);
		EditText task_description = (EditText) findViewById(R.id.task_description_input);
		
		//May need validate before commit to DB!
		AchievementTask task = new AchievementTask(
			task_title.getText().toString(),
			task_description.getText().toString()
		);
		
		AchievementAdapter adapter = new AchievementAdapter(this);
		boolean addResult = false;
		try {
			adapter.open();
			addResult = adapter.addAchievementTask(task);
		}
		finally
		{
			adapter.close();
		}
		if (!addResult) {
			MessageHelper.showMsg(this, "Error", "Unable to create task");
		} else {
			TaskList.expireCurrentView();
			finish();
		}
	}
}
